package com.key.controller.admin.systemSetting;

import com.github.pagehelper.PageHelper;
import com.key.common.R;
import com.key.entity.Employee;
import com.key.entity.SysRole;
import com.key.service.EmployeeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author：朕
 * @Package：com.key.controller.admin.systemSetting
 * @Project：ams_system
 * @name：Employee
 * @Date：2023/2/18 13:10
 * @Filename：Employee
 */

@Controller
@Api(value = "员工信息",tags = "员工信息API")
@RequestMapping(value = "/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;



    @RequestMapping(value = "/findEmployee",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "显示员工",notes = "",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",paramType = "query",dataType = "int",required = true)
    })
    public R findEmployee(int currentPage,int pageSize){
        R r = new R();
        PageHelper.startPage(currentPage,pageSize);
        List<Employee> employees = employeeService.findEmployee();
        if(employees.size()>0){
            r.setCode(200);
            r.setMsg("显示成功");
            r.setData(employees);
            return r;
        }else{
            r.setCode(500);
            r.setMsg("显示失败");
            return r;
        }
    }


    @RequestMapping(value = "addEmployee",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "员工的增加",notes = "员工的实体类",httpMethod = "post",response = R.class)
    public R addEmployee(@RequestBody @ApiParam(name = "Employee",value = "增添员工的实体类",required = true) Employee employee){
        R r = new R();
        boolean e =  employeeService.addEmployee(employee);
        if(e == true){
            r.setCode(200);
            r.setMsg("增加成功");
            return r;
        }else{
            r.setCode(500);
            r.setMsg("增加失败");
            return r;
        }
    }


    @RequestMapping(value = "/deleteEmployee",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除员工",notes = "传递员工工号",httpMethod = "get",response = R.class)
    public R deleteEmployee(@RequestBody @ApiParam(name = "employeeId",value = "删除",required = true) Integer employeeId) {
        R r = new R();
        boolean e = employeeService.deleteEmployee(employeeId);
        if(e == true){
            r.setCode(200);
            r.setMsg("增加成功");
            return r;
        }else{
            r.setCode(200);
            r.setMsg("增加失败");
            return r;
        }
    }


    @RequestMapping(value = "/findSysEmployeeById",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据员工编号查询",notes = "传递查询的员工编号",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "employeeId",value = "员工编号",paramType = "query",dataType = "String",required = true)
    })
    public R findSysEmployeeById(Integer currentPage,Integer pageSize,Integer employeeId){
        R r = new R();
        PageHelper.startPage(currentPage,pageSize);
        List<Employee> employees = employeeService.findEmployeeById(employeeId);
        if(employees.size()>0){
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(employees);
            return r;
        }else{
            r.setCode(200);
            r.setMsg("查询失败");
            return r;
        }
    }


    @RequestMapping(value = "/updateEmployee",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改员工",notes = "传递修改的参数",httpMethod = "post",response = R.class)
    public R updateEmployee(@RequestBody @ApiParam(name = "Employee",value = "员工的修改信息",required = true) Employee employee){
        R r = new R();
        boolean e = employeeService.updateEmployee(employee);
        if(e == true){
            r.setCode(200);
            r.setMsg("修改成功");
            return r;
        }else{
            r.setCode(500);
            r.setMsg("修改失败");
            return r;
        }
    }


}
